package com.zzx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzx.domain.Order;
import com.zzx.domain.tv.OrderList;
import com.zzx.exception.ExceptionState;
import com.zzx.mapper.OrderMapper;
import com.zzx.service.OrderService;
import com.zzx.util.ResponseResult;
import org.mockito.internal.matchers.Or;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 订单表(Order)表服务实现类
 *
 * @author makejava
 * @since 2022-08-02 18:15:11
 */
@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    /**
     * 获取订单列表
     * @param query
     * @param pagenum
     * @param pagesize
     * @return
     */
    @Override
    public ResponseResult getOrderList(String query, Integer pagenum, Integer pagesize) {
        Page<Order> page = new Page<>(pagenum, pagesize);
        LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.hasText(query),Order::getOrderNumber,query);
        page(page,wrapper);
        List<OrderList> collect = page.getRecords().stream().map(item ->
                new OrderList(item.getOrderId(), item.getUserId(), item.getOrderNumber(), item.getOrderPrice(), item.getOrderPay(), item.getIsSend(), item.getTradeNo(), item.getOrderFapiaoTitle(), item.getOrderFapiaoCompany(), item.getOrderFapiaoContent(), item.getConsigneeAddr(), item.getPayStatus(), item.getCreateTime(), item.getUpdateTime())
        ).collect(Collectors.toList());
        Map map = new HashMap<>();
        map.put("total",page.getTotal());
        map.put("pagenum",page.getCurrent());
        map.put("goods",collect);
        return new ResponseResult("获取成功", ExceptionState.OK,map);
    }

    /**
     * 通过id修改订单状态
     * @param id
     * @return
     */
    @Override
    public ResponseResult getOrderById(Long id) {
        return null;
    }
}

